package io.github.wanggit.antcms.server.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.github.wanggit.antcms.server.domain.AntCatalog;

import java.util.ArrayList;
import java.util.List;

public class CatalogDTO extends AntCatalog {

    /** 树节点层级，1开始 */
    private short lv;

    private boolean leaf = true;

    @JsonIgnore private CatalogDTO parentNode;

    @JsonIgnore private List<CatalogDTO> children = new ArrayList<>();

    public static CatalogDTO from(AntCatalog catalog) {
        CatalogDTO catalogDTO = new CatalogDTO();
        catalogDTO.setAliasName(catalog.getAliasName());
        catalogDTO.setArticlesCount(catalog.getArticlesCount());
        catalogDTO.setId(catalog.getId());
        catalogDTO.setName(catalog.getName());
        catalogDTO.setParentId(catalog.getParentId());
        catalogDTO.setRemark(catalog.getRemark());
        catalogDTO.setUpdateTime(catalog.getUpdateTime());
        return catalogDTO;
    }

    public short getLv() {
        return lv;
    }

    public void setLv(short lv) {
        this.lv = lv;
    }

    public boolean isLeaf() {
        return leaf;
    }

    public void setLeaf(boolean leaf) {
        this.leaf = leaf;
    }

    public CatalogDTO getParentNode() {
        return parentNode;
    }

    public void setParentNode(CatalogDTO parentNode) {
        this.parentNode = parentNode;
    }

    public CatalogDTO addChild(CatalogDTO child) {
        this.children.add(child);
        return this;
    }

    public List<CatalogDTO> getChildren() {
        return children;
    }

    public void setChildren(List<CatalogDTO> children) {
        this.children = children;
    }
}
